#include "widget.h"
#include "ui_widget.h"
#include<QDebug>
#include<QShortcut>

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    ui->horizontalSlider->setValue(800);
    ui->horizontalSlider->setMaximum(2000);
    ui->horizontalSlider->setMinimum(500);
    ui->horizontalSlider->setSingleStep(400);
//    ui->horizontalSlider->setInvertedAppearance(true);

    ui->verticalSlider->setValue(800);
    ui->verticalSlider->setMaximum(2000);
    ui->verticalSlider->setMinimum(500);
    ui->verticalSlider->setSingleStep(400);
    //翻转朝向，默认滑块从下向上增长，改成从上往下增长
    ui->verticalSlider->setInvertedAppearance(true);

    //设置快捷键
    QShortcut*shortcut1=new QShortcut(this);
    //增加
    shortcut1->setKey(Qt::Key_W);
    //activated当快捷键被按下且触发成功时发出
    connect(shortcut1,&QShortcut::activated,this,&Widget::addValue);
    //减少
    QShortcut*shortcut2=new QShortcut(this);
    shortcut2->setKey(Qt::Key_S);
    connect(shortcut2,&QShortcut::activated,this,&Widget::subValue);


    //设置快捷键
    QShortcut*shortcut3=new QShortcut(this);
    shortcut3->setKey(Qt::Key_A);
    connect(shortcut3,&QShortcut::activated,this,&Widget::A_sub);

    QShortcut*shortcut4=new QShortcut(this);
    shortcut4->setKey(Qt::Key_D);
    connect(shortcut4,&QShortcut::activated,this,&Widget::D_add);
}

Widget::~Widget()
{
    delete ui;
}

void Widget::subValue()
{
    int value=ui->verticalSlider->value();
    ui->verticalSlider->setValue(value-20);
}

void Widget::addValue()
{
    int value=ui->verticalSlider->value();
    ui->verticalSlider->setValue(value+20);
}

void Widget::A_sub()
{
    int value=ui->horizontalSlider->value();
    ui->horizontalSlider->setValue(value-20);
}

void Widget::D_add()
{
    int value=ui->horizontalSlider->value();
    ui->horizontalSlider->setValue(value+20);
}


void Widget::on_verticalSlider_valueChanged(int value)
{


    QString s=QString("verticalSlider: ")+QString::number(value);
    ui->label_vertical->setText(s);
    QRect rect=this->geometry();
    this->setGeometry(rect.x(),rect.y(),rect.width(),value);
    qDebug()<<value;
}

void Widget::on_horizontalSlider_valueChanged(int value)
{

    QString s=QString("horizontalSlider: ")+QString::number(value);
    ui->label_horizontal->setText(s);
    QRect rect=this->geometry();
    this->setGeometry(rect.x(),rect.y(),value,rect.height());
    qDebug()<<value;
}
